package utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

/**
 * Parte importante del progetto. formatta le stringhe contenute negli ArrayList
 * che riceve dai tre {@link file}, sfrutta (ovviamente) il formato nei file e
 * bisogna modificare solo questa classe in caso di aggiustamenti nel formato;
 * per interpretare la formattazione vedere direttamente i file
 * 
 * @author koelio
 * @see FileLoader
 * @see IFormatter
 * 
 */
public class Formatter implements IFormatter {

	Map<String, List<String>> teams = new HashMap<String, List<String>>();
	Map<String, List<String>> faculties = new HashMap<String, List<String>>();
	Map<String, Integer> rounds = new HashMap<String, Integer>();
	StringTokenizer tok;

	public Formatter(FileLoader file) {

		for (int i = 0; i < file.getTeams().size(); i++) {
			tok = new StringTokenizer(file.getTeams().get(i));

			String tmp = tok.nextToken();

			List<String> list = new ArrayList<String>();

			while (tok.hasMoreTokens()) {

				list.add(tok.nextToken(","));

			}
			// System.out.println(tmp);
			// System.out.println(list);
			this.teams.put(tmp, list);

		}

		for (int i = 0; i < file.getFaculties().size(); i++) {
			tok = new StringTokenizer(file.getFaculties().get(i));

			String tmp = tok.nextToken();
			List<String> list = new ArrayList<String>();
			while (tok.hasMoreTokens()) {

				list.add(tok.nextToken(","));

			}
			// System.out.println(tmp);
			// System.out.println(list);
			this.faculties.put(tmp, list);
		}

		for (int i = 0; i < file.getRounds().size(); i++) {
			tok = new StringTokenizer(file.getRounds().get(i));

			this.rounds.put(tok.nextToken(), Integer.parseInt(tok.nextToken()));

		}

		// System.out.println(rounds);

	}

	@Override
	public Map<String, List<String>> getTeams() {
		return teams;
	}

	@Override
	public Map<String, List<String>> getFaculties() {
		// TODO Auto-generated method stub
		return faculties;
	}

	@Override
	public Map<String, Integer> getRounds() {
		// TODO Auto-generated method stub
		return rounds;
	}

}
